package com.example.forum.controller;


import com.example.forum.common.AppResult;
import com.example.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@Api(tags = "测试类的相关接口")
@RestController
@RequestMapping("/test")
public class TestController {

    @ApiOperation("测试接口1，显示hello 论坛系统")
    @GetMapping("/hello")
    public String hello() {
        return "hello 论坛系统";
    }

    @ApiOperation("测试接口2，显示抛出异常信息")
     @GetMapping("/exception")
    public AppResult testException() throws Exception {
        throw new Exception("这是一个Exception");
    }

    @ApiOperation("测试接口3，显示抛出的自定义异常")
    @GetMapping("/appException")
    public AppResult testApplicationException() {
        throw  new ApplicationException("这是一个Application");
    }

    @ApiOperation("测试接口4，按插入的名字显示你好信息")
    @PostMapping("/helloByName")
    public AppResult helloByName(@ApiParam(value = "姓名")@RequestParam("name") String name) {
        return AppResult.success("hello " + name);
    }
}
